package zyb.myproject;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

//购物车
public class Cart {

	public List<Goods> list = new ArrayList<>();

	private double total = 0;

	// 往购物车里添加商品
	public void addCart(Goods goods) {

		list.add(goods);
	}

	// 展示购物车，
	public void showGoods() {

		System.out.println("***********购物车列表*************");
		Iterator<Goods> iter = list.iterator();
		while (iter.hasNext()) {
			Goods goods = iter.next();
			System.out.println("商品名称：" + goods.getGoodName() + ",商品价格：" + goods.getPrice() + ",购买数量：" + goods.getNum());
		}

	}

	// 购物车商品计算总价
	public double calu() {

		Iterator<Goods> iter = list.iterator();
		while (iter.hasNext()) {
			Goods goods = iter.next();
			total = total + goods.getPrice() * goods.getNum();
		}
		return total;
	}
}
